package com.tensquare.gathering.service;

import com.tensquare.gathering.dao.GatheringDao;
import com.tensquare.gathering.pojo.Gathering;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author Macross
 * @Type GatheringService.java
 * @Desc
 * @date 2019/12/17 20:36
 */
@Service
public class GatheringService {

    @Autowired
    private GatheringDao gatheringDao;

    /**
     * 获取指定的活动信息
     * @param gatheringId 活动id
     * @return
     */
    @Cacheable(value = "gathering",key = "'gathering_'+#gatheringId")
    public Gathering findById(String gatheringId){
        return gatheringDao.findById(gatheringId).orElse(null);
    }

    /**
     * 更新指定的活动信息
     * @param gathering 活动信息
     */
    @CacheEvict(value = "gathering",key = "'gathering_'+#gathering.id")
    public void updateGathering(Gathering gathering){
        gatheringDao.save(gathering);
    }

    /**
     * 删除指定的活动信息
     * @param gatheringId 活动id
     */
    @CacheEvict(value = "gathering",key = "'gathering_'+#gatheringId")
    public void deleteGathering(String gatheringId){
        gatheringDao.deleteById(gatheringId);
    }
}
